// pages/login/login.js
import { request } from '../../request/index.js'

Page({
  data: {
    username: '系统管理员',
    password: '12345678',
  },
  login() {
    let data = {
      name: this.data.username,
      password: this.data.password
    }
    request({
      url: '/user/login',
      method: 'POST',
      data: data,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 设置请求头为表单数据格式
      }
    }).then(res => {
      if (res.code === 0){
        wx.showToast({
          title: '登陆成功',
          icon: 'success'
        })
        wx.setStorageSync('user', res)

        setTimeout(() => {
          wx.navigateTo({
            url: '../../custom-tab-bar/index',
            routeType: 'routeType',
            success: (result) => {},
            fail: (res) => {},
            complete: (res) => {},
          },1000)
        }
        )
      } else {
        wx.showToast({
          title: '账号或密码错误',
          icon: 'error'
        })
      }
    })
  }
})